package com.vito.oa.act.extend.action;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.authoriza.cache.SessionMap;
import com.vito.base.authoriza.model.UserModel;
import com.vito.base.model.DataGrid;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.base.util.Validata;
import com.vito.oa.act.constant.OaActContants;
import com.vito.oa.act.extend.model.OaTaskModel;
import com.vito.oa.act.extend.service.OaActivitiWaitMatterService;
/**
 * 待办事项action类
 *
 */
@Controller
@RequestMapping("oa/act/activitiWaitMatter")
public class OaActivitiWaitMatterAction extends BaseAction {
	
	private static final Logger log = LoggerFactory.getLogger(OaActivitiWaitMatterAction.class);
	
	@Reference
	private OaActivitiWaitMatterService waitMatterService;
	@RequestMapping("getWaitDoneByPaged")
	@ResponseBody
	public Result queryWaitDoneByPage(OaTaskModel task) {
		Result res = new Result();
		try{
			//获取当前登录用户
			UserModel user = (UserModel) SessionMap.getObj();
			if(user == null || Validata.isNullOrEmpty(user.getUserId())){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			task.setUserId(user.getUserId());
			//默认取审批模块
			if(Validata.isNullOrEmpty(task.getMoudelType())){
				task.setMoudelType(OaActContants.PROCESS_MOUDEL_TYPE_APPROVAL);
			}
			DataGrid<Map<String,String>> page = waitMatterService.queryOaWaitDoneByPage(task);
			if(page.getTotal()!=0){
				res.setCode(Result.CODE_OK);
				res.setData(page);
			}else{
				res.setCode(Result.CODE_OK);
				res.setMsg("暂无数据");
			}
		}catch(Exception ex){
			log.error("查询异常",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg("查询异常");
		}
		return res ;
	}
	@RequestMapping("queryWaitDoneByPageCount")
	@ResponseBody
	public Result queryWaitDoneByPageCount(OaTaskModel task) {
		Result res = new Result();
		try{
			//获取当前登录用户
			UserModel user = (UserModel) SessionMap.getObj();
			if(user == null || Validata.isNullOrEmpty(user.getUserId())){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			task.setUserId(user.getUserId());
			task.setDepts(user.getDepts());
			//默认取审批模块
			if(Validata.isNullOrEmpty(task.getMoudelType())){
				task.setMoudelType(OaActContants.PROCESS_MOUDEL_TYPE_APPROVAL);
			}
			Integer count = waitMatterService.queryWaitDoneByPageCount(task);
			Map<String,Object> data = new HashMap<String, Object>();
			data.put("waitDoneCount", count);
			res.setCode(Result.CODE_OK);
			res.setData(data);
		}catch(Exception ex){
			log.error("查询异常",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg("查询异常");
		}
		return res ;
	}
}
